package com.zjl.litemall.admin.controller;

import com.zjl.litemall.core.util.ResponseUtil;
import com.zjl.litemall.db.domain.LitemallAdmin;
import com.zjl.litemall.db.service.LitemallNoticeAdminService;
import io.swagger.annotations.Api;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author cat
 * @description
 * @date 2022/2/25 下午5:31
 */

@RestController
@RequestMapping("/admin/profile")
@Api(tags = "状态检查接口")
public class AdminProfileController {

    @Autowired
    private LitemallNoticeAdminService noticeAdminService;

    /**
     * @description 登陆进来此接口不断报错404。shiro相关，下来再看
     *
     * @updateTime 2022/2/25 下午9:49
     */
    @RequiresAuthentication
    @GetMapping("/nnotice")
    public Object nNotice() {
        int count = noticeAdminService.countUnread(getAdminId());
        return ResponseUtil.ok(count);
    }

    // 返回主键ID
    private Integer getAdminId(){
        Subject currentUser = SecurityUtils.getSubject();
        LitemallAdmin admin = (LitemallAdmin) currentUser.getPrincipal();
        return admin.getId();
    }

}
